home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / utils / file / fileutil.13 / fileutil / fileutils-3.13 / src / cp-aux.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-07-06  |  3.8 KB  |  102 lines

  1. /* cp-aux.c  -- file copying (auxiliary routines)
  2.    Copyright (C) 89, 90, 91, 95, 1996 Free Software Foundation.
  3.  
  4.    This program is free software; you can redistribute it and/or modify
  5.    it under the terms of the GNU General Public License as published by
  6.    the Free Software Foundation; either version 2, or (at your option)
  7.    any later version.
  8.  
  9.    This program is distributed in the hope that it will be useful,
  10.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.    GNU General Public License for more details.
  13.  
  14.    You should have received a copy of the GNU General Public License
  15.    along with this program; if not, write to the Free Software Foundation,
  16.    Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  17.  
  18.    Written by Torbjorn Granlund, Sweden (tege@sics.se). */
  19.  
  20. #include <config.h>
  21. #include <stdio.h>
  22.  
  23. #include "cp.h"
  24.  
  25. extern char *program_name;
  26.  
  27. void
  28. usage (int status, const char *reason)
  29. {
  30.   if (reason != NULL)
  31.     fprintf (status == 0 ? stdout : stderr, "%s: %s\n",
  32.          program_name, reason);
  33.  
  34.   if (status != 0)
  35.     fprintf (stderr, _("Try `%s --help' for more information.\n"),
  36.          program_name);
  37.   else
  38.     {
  39.       printf (_("\
  40. Usage: %s [OPTION]... SOURCE DEST\n\
  41.   or:  %s [OPTION]... SOURCE... DIRECTORY\n\
  42. "),
  43.           program_name, program_name);
  44.       printf (_("\
  45. Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.\n\
  46. \n\
  47.   -a, --archive                same as -dpR\n\
  48.   -b, --backup                 make backup before removal\n\
  49.   -d, --no-dereference         preserve links\n\
  50.   -f, --force                  remove existing destinations, never prompt\n\
  51.   -i, --interactive            prompt before overwrite\n\
  52.   -l, --link                   link files instead of copying\n\
  53.   -p, --preserve               preserve file attributes if possible\n\
  54.   -r                           copy recursively, non-directories as files\n\
  55.       --sparse=WHEN            control creation of sparse files\n\
  56.   -s, --symbolic-link          make symbolic links instead of copying\n\
  57.   -u, --update                 copy only older or brand new files\n\
  58.   -v, --verbose                explain what is being done\n\
  59.   -x, --one-file-system        stay on this file system\n\
  60.   -P, --parents                append source path to DIRECTORY\n\
  61.   -R, --recursive              copy directories recursively\n\
  62.   -S, --suffix=SUFFIX          override the usual backup suffix\n\
  63.   -V, --version-control=WORD   override the usual version control\n\
  64.       --help                   display this help and exit\n\
  65.       --version                output version information and exit\n\
  66. \n\
  67. By default, sparse SOURCE files are detected by a crude heuristic and the\n\
  68. corresponding DEST file is made sparse as well.  That is the behavior\n\
  69. selected by --sparse=auto.  Specify --sparse=always to create a sparse DEST\n\
  70. file whenever the SOURCE file contains a long enough sequence of zero bytes.\n\
  71. Use --sparse=never to inhibit creation of sparse files.\n\
  72. \n\
  73. "));
  74.       printf (_("\
  75. The backup suffix is ~, unless set with SIMPLE_BACKUP_SUFFIX.  The\n\
  76. version control may be set with VERSION_CONTROL, values are:\n\
  77. \n\
  78.   t, numbered     make numbered backups\n\
  79.   nil, existing   numbered if numbered backups exist, simple otherwise\n\
  80.   never, simple   always make simple backups\n\
  81. "));
  82.       printf (_("\
  83. \n\
  84. As a special case, cp makes a backup of SOURCE when the force and backup\n\
  85. options are given and SOURCE and DEST are the same name for an existing,\n\
  86. regular file.\n"));
  87.     }
  88.   exit (status);
  89. }
  90.  
  91. int
  92. is_ancestor (const struct stat *sb, const struct dir_list *ancestors)
  93. {
  94.   while (ancestors != 0)
  95.     {
  96.       if (ancestors->ino == sb->st_ino && ancestors->dev == sb->st_dev)
  97.     return 1;
  98.       ancestors = ancestors->parent;
  99.     }
  100.   return 0;
  101. }
  102.